'use strict';

const Service = require('egg').Service;

class AdminService extends Service {
   /**
    * 
    * 添加项目
    * @param {any} params 
    * @returns 
    * @memberof AdminService
    */
   async addProjectModel(params){
        let result =await this.app.mysql.insert('tab_system',params);
        return {
            rows:result.affectedRows
        }
    }
    /**
     * 删除项目
     * 
     * @param {any} id 项目id
     * @returns 
     * @memberof AdminService
     */
    async deleteProjectModel(id){
        // let result =await this.app.mysql.delete('tab_system',{
        //     system_id:id
        // })
        let result =await this.app.mysql.query(`
    DELETE 
        t1.* ,
        t2.*
    FROM
        tab_system AS t1
    LEFT JOIN 
        tab_api AS t2 ON t1.system_id = t2.system_id
    WHERE
        t1.system_id  = '${id}'`)
        return {
            rows:result.affectedRows
        }
    }

    async editProjectModel(params) {
        let result = await this.app.mysql.query(`
        UPDATE
            tab_system
        SET
            system_name = '${params.system_name} ',
            system_version = '${params.system_version} ',
            system_desc = '${params.system_desc} ',
            system_url='${params.system_url}',
            user_id ='${params.user_id}',
            system_time='${params.system_time}'
        WHERE
            system_id = '${params.system_id}'
    `);
        return {
            rows: result.affectedRows
        }
    }
}

module.exports = AdminService;
